<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYDCONN();
	if(!isset($_GET['CODE'])) { $_GET['CODE'] = 0; }
	function TreeNode($Parent,$GET) {
	if($Parent == 0) { echo '<ul class="tree">'; } else { echo '<ul>'; }
	for ($a = 1; $a <= $GET[0]; $a++) {
		if($Parent==$GET[$a]['ParentCODE']) {
	echo '<li>';
	
			if ($GET[$a]['Type'] == 0) {
		echo '<b><a onclick="document.edtCdcInvoice.CODE.value='.$GET[$a]['CODE'].';document.edtCdcInvoice.CODEDESCRIPTION.value=\''.$GET[$a]['name'].'\';document.edtCdcInvoice.action=\'Modules/CentrodeCustos/Lib/sel_provider.php\';subform(\'edtCdcInvoice\',\'ProviderDiv\');Ext.getCmp(\'winccaccount\').close();">
		'.$GET[$a]['CODE']." ".$GET[$a]['name'].'</a></b>';
			} else {
			echo $GET[$a]['CODE'].' - '.$GET[$a]['name'].' <input name="AddConta" type="button" class="addbutton" value="Abrir Conta" id="AddConta" onClick="getscreen(\'addconta.php\');">';

			TreeNode($GET[$a]['CODE'],$GET);
			}
	echo '</li>';
		 }
		}
	echo '</ul>';
	} 
if (isset($_GET['FormTree'])) {
	if (isset($_GET['Iv'])) {
		$_GET['jB'] = $_GET['jB'].'&Iv='.$_GET['Iv'];
	}
	$GET = $GLOBALS['MYD']->db_array("SELECT name,CODE,ParentCODE,Type
		FROM ccenter_contas WHERE Type IN (0,1) ORDER BY ccenter_contas.CODE ASC"); 
echo '<div style="height:380px;overflow:auto">';
	TreeNode(0,$GET);
	echo '</div>';
		}
	form_pr('elmform','','','post');
	mn_field('hidden','ED','CODE',$_GET['CODE'],'','','','');
if (isset($_GET['FormProvider'])) { 
echo '<table  border="0" cellpadding="3" cellspacing="1">
  <tr>
    <td>Nome<br>'; mn_field('text','ED','name','','','38','',''); 
	  echo '</td></tr>
  <tr>
    <td>Tipo<br>'; mn_field('hselect','ED','TYPE','',"Externo;Interno#2;1",'','',''); 
	  echo '</td>
    </tr>
  <tr>
    <td>NIF<br>'; mn_field('text','ED','NIF','','','','',''); 
	  echo '</td></tr>
  <tr>
        <td>'; mn_field('button','ED','saveProvider','Adicionar','','','','" onclick="
		document.elmform.action=\'_response/rsproxy.php?pr=cdc_providers\';
		subform(\'elmform\',\'divLApp\');'); 
	echo '</td></tr>
 </table>';
		}
if (isset($_GET['FormContract'])) { 
	mn_field('hidden','ED','Provider',$_GET['Prov'],'','','','');
echo '<table  border="0" cellpadding="3" cellspacing="1">
  <tr>
    <td>Descrição<br>';
	mn_field('text','ED','Desc','','38','','',''); 
	  echo '</td></tr>
  <tr>
    <td>Nº Cliente<br>';
	mn_field('text','ED','Client','','','','',''); 
	  echo '</td></tr>
  <tr>
    <td>NIB<br>';
	mn_field('text','ED','NIB','','28','','',''); 
	  echo '</td></tr>
  <tr>
    <td width="20%">';
	mn_field('button','ED','saveContract','Adicionar','','','','" onclick="
		document.elmform.action=\'_response/rsproxy.php?pr=cdc_contracts\';
		subform(\'elmform\',\'divLApp\');'); 
	echo '</td>
    </tr>
 </table>';
		}
echo '</form>
<div id="divLApp"></div>'; ?>